﻿/**
 * @author Administrator
 */
function moveSelectEmp(willSelectLbxName, selectTargetLbxName, target){
    var willSelect = document.getElementById(willSelectLbxName);
    var targetSelect = document.getElementById(selectTargetLbxName);
    var selectEmpCollection = new Array();
    var s = 0;
    for (var i = 0; i < willSelect.options.length; i++) {
        if (willSelect.options[i].selected) {
            var myOp = willSelect.options[i];
            targetSelect.appendChild(myOp);
            selectEmpCollection[s] = myOp.value;
            myOptionsLabel[s] = myOp.text;
            s++;
            i--;
        }
    }
    document.getElementById("selectedEmpCollection").value = selectEmpCollection;
    myOptions = new Array();
    if (target == 'right') {
        for (var x = 0; x < willSelect.options.length; x++) {
            myOptions[x] = willSelect.options[x];
        }
    }
    else {
        for (var x = 0; x < targetSelect.options.length; x++) {
            myOptions[x] = targetSelect.options[x];
        }
    }
}

function moveALLSelectEmp(willSelectLbxName, selectTargetLbxName, target){
    var willSelect = document.getElementById(willSelectLbxName);
    var targetSelect = document.getElementById(selectTargetLbxName);
    var selectEmpCollection = new Array();
    var s = 0;
    for (var i = 0; i < willSelect.options.length;) {
        var myOp = willSelect.options[i];
        targetSelect.appendChild(myOp);
        selectEmpCollection[s] = myOp.value;
        myOptionsLabel[s] = myOp.text;
        s++;
    }
    document.getElementById("selectedEmpCollection").value = selectEmpCollection;
    myOptions = new Array();
    if (target == 'right') {
        for (var x = 0; x < willSelect.options.length; x++) {
            myOptions[x] = willSelect.options[x];
        }
    }
    else {
        for (var x = 0; x < targetSelect.options.length; x++) {
            myOptions[x] = targetSelect.options[x];
        }
    }
}

/////////////////////////////////////////////////////////////////////////
var myOptions = new Array();
var myOptionsLabel = new Array();

function loadOptions(target){
    var targets = document.getElementById(target);
    for (var i = 0; i < targets.options.length; i++) {
        myOptions[i] = targets.options[i];
    }
}

function willSelectOneTxtValueChange(resource, target){
    var resource = document.getElementById(resource);
    var target = document.getElementById(target);
    clearOptions(target);
    if (resource.value != "") {
        for (var j = 0; j < myOptions.length; j++) {
            var myTarOp = myOptions[j];
            if (resource.value.toLowerCase() == myTarOp.text.toLowerCase().substr(0, resource.value.length)) {
                target.appendChild(myTarOp);
            }
        }
        if (target.options.length == 0) {
            selectOneValueChange(myOptions, target);
        }
    }
    else {
        selectOneValueChange(myOptions, target);
    }
}

function selectOneValueChange(myOptions, target){
    for (var m = 0; m < myOptions.length; m++) {
        target.appendChild(myOptions[m]);
    }
}

function clearOptions(target){
    for (var i = 0; i < target.options.length;) {
        target.removeChild(target.options[i]);
    }
}

/////////////////////////////////////////////////////////////////////

function checkSendTarget(target, msgContent){
    var sendTarget = document.getElementById(target);
    var msg = document.getElementById(msgContent).value;
    var selectCount = 0;
    if (target == 'sectionShowLbx' || target == 'someGroupLtx') {
        if (sendTarget.options.length > 0) {
            for (var i = 0; i < sendTarget.options.length; i++) {
                if (sendTarget.options[i].selected) {
                    selectCount++;
                }
            }
            if (selectCount == 0) {
                alert('请选择发送目标！');
                return false;
            }
        }
        else {
            alert('没有可选发送目标!');
            return false;
        }
    }
    else {
        if (sendTarget.options.length == 0) {
            alert('请选择发送目标！');
            return false;
        }
            else {
                var seloptions = sendTarget.options;
                for(var i = 0; i < seloptions.length; i++) {
                    seloptions[i].selected = true;
                } 
                return true;
            }
    }
}

//将选择的部门信息存入数组中
function getTargetSectionCollection(target, save){
    var c = 0;
    var targetSection = document.getElementById(target);
    var tSections = new Array();
    for (var i = 0; i < targetSection.options.length; i++) {
        var section = targetSection.options[i];
        if (section.selected) {
            tSections[c] = section.value;
            c++;
        }
    }
    document.getElementById(save).value = tSections;
}

//删除短消息选择效果
function allMsgCheck(cur){
    var chks = document.getElementsByTagName("input");
    for (var i = 0; i < chks.length; i++) {
        var chkCur = chks[i];
        if (chkCur.type.toLowerCase() == "checkbox" && chkCur.name == cur) {
            if (chkCur.checked == false) {
                chkCur.checked = true;
            }
            else {
                chkCur.checked = false;
            }
        }
    }
}

//检查删除内容是否为空
function checkDelMsg(target){
    var chks = document.getElementsByTagName("input");
    var state = 0;
    for (var i = 0; i < chks.length; i++) {
        var chkCur = chks[i];
        if (chkCur.type.toLowerCase() == "checkbox" && chkCur.name == target) {
            if (chkCur.checked == true) {
                state++;
            }
        }
    }
    if (state == 0) {
        alert('请勾选要删除的信息！');
        return false;
    }
    else {
        return true;
    }
}

//检查上传文件是否为空
function checkUploadFile(target){
    var fileValue = document.getElementById(target).value;
    if (fileValue == "") {
        alert("请选择要上传文件!");
        return false;
    }
    else {
        return true;
    }
}

//将给每个人的上传文件路径保存到已自己登录名称命名的变量中
function toGetSelfFilePath(){
    var filePaths = document.getElementById("emailTarget").value.split(',');
    for (var i = 0; i < filePaths.length; i++) {
    
    }
}

//检查要删除的上传文件
function checkDelUploadFile(target){
    var chkTarget = document.getElementById(target);
    if (chkTarget.options.length == 0) {
        alert('还没有上传的文件供删除！');
        return false;
    }
    else {
        var state = false;
        for (var i = 0; i < chkTarget.options.length; i++) {
            if (chkTarget.options[i].selected) {
                state = true;
            }
        }
        if (state) {
            return true;
        }
        else {
            alert('请选择要删除的文件!');
            return false;
        }
    }
}

//验证是否有发送目标以供上传附件
function checkEmailTarget(target){
    if (document.getElementById(target).options.length == 0) {
        alert('请选择邮件的接收人!');
        return false;
    }
    else {
        var args = new Array();
        args[0] = document.getElementById('selectedEmpCollection').value;
        args[1] = myOptionsLabel;
        openFileUpload(args, 'inform');
    }
}

//打开模态文件上传窗口
function openFileUpload(obj, type){
    result = window.showModalDialog('../UserFile/FileUpload.aspx?st=' + type, obj, 'status:no;center:yes;scroll:no;resizable:no;help:no;dialogWidth:600px;dialogHeight:380px');
    if (result == null) {
        //alert('您未正常退出，请上传文件后点击\"确定并返回\"按钮正常退出!');
		result = "";
    }
    else {
        
    }
	document.getElementById('uploadFilePaths').value = result;
}

//模态窗口接收参数
function getSendArgs(){
    var sargs = window.dialogArguments;
    if (sargs != null) {
        document.getElementById('emailTarget').value = sargs[0];
        document.getElementById('emailTargetUsername').value = sargs[1];
    }
}

//模态窗口返回值方法
//function modalDialog(target, fileList){
//    if (document.getElementById(target).value == "") {
//        alert('请选择要上传的文件');
//        return false;
//    }
//    else {
//        var myOption = document.createElement("option");
//        var optionValue = document.getElementById(target).value;
//        var optionText = document.getElementById(target).value.substr(document.getElementById(target).value.lastIndexOf("\\") + 1);
//        myOption.title = optionValue;
//        myOption.label = optionText;
//        myOption.value = optionValue;
//        document.getElementById(fileList).appendChild(myOption);
//        document.getElementById(target).value = "";
//    }
//}

function getReturnValue(fileList){
    if (document.getElementById(fileList).options.length > 0) {
        var retuValues = "";
        var fileList = document.getElementById("ltbUploadFiles");
        for (var i = 0; i < fileList.options.length; i++) {
            if (i == fileList.options.length - 1) {
                retuValues += fileList.options[i].value;
            }
            else {
                retuValues += fileList.options[i].value + ",";
            }
        }
        window.returnValue = retuValues;
    }
    else {
        window.returnValue = "";
    }
    window.close();
}

function delFileList(target){
    var state = false;
    if (document.getElementById(target).options.length == 0) {
        alert('没有文件可供删除!');
        return false;
    }
    else {
        for (var i = 0; i < document.getElementById(target).options.length; i++) {
            if (document.getElementById(target).options[i].selected) {
                state = true;
            }
        }
        if (state) {
            for (var i = 0; i < document.getElementById(target).options.length; i++) {
                if (document.getElementById(target).options[i].selected) {
                    document.getElementById(target).removeChild(document.getElementById(target).options[i]);
                    i--;
                }
            }
        }
        else {
            alert('请选择要删除的文件');
            return false;
        }
    }
}

//验证发表日记
function checkWriteDiary(title, content){
	titles = document.getElementById(title).value;
	contents = document.getElementById(content).value;
	if(titles == ""){
		alert('请填写标题！');
		return false;
	}
	if(contents == ""){
		alert('请填写日记内容！');
		return false;
	}
	return true;
}

//验证按指定日期查找日记
function checkRangeOfDate(start, end){
	startValue = document.getElementById(start).value;
	endValue = document.getElementById(end).value;
	if(startValue == ""){
		alert('请选择起始日期！');
		return false;
	}
	if(endValue == ""){
		alert('请选择结束日期！');
		return false;
	}
	return true;
}

//导出日记模态窗口
function openExportDiary(obj){
	content = document.getElementById(obj).value;
	result = window.showModalDialog('../UserFile/ExportDiary.aspx', content, 'status:no;center:yes;scroll:no;resizable:no;help:no;dialogWidth:430px;dialogHeight:120px');
}

//日记模态窗口接受参数
function getSendParameter(target){
	document.getElementById(target).value = window.dialogArguments;
}

//日记模态窗口检查导出路径
function checkTargetPath(target){
	if(document.getElementById(target).value == ""){
		alert('请选择导出路径！');
		return false;
	}
	return true;
}
